package com.temperate;

import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author:wesley
 */
public class TempReduce extends Reducer<TempKey, DoubleWritable, Text, NullWritable> {

    @Override
    public void reduce(TempKey key, Iterable<DoubleWritable> values, Context context) throws IOException, InterruptedException {

        int i = 0;

        for (DoubleWritable value : values) {
            i++;
            String msg = key.getYear() + "\t" + key.getMonth() + "\t" + value.get();
            context.write(new Text(msg), NullWritable.get());
            if (i == 3) {
                break;
            }
        }
    }
}
